import { Controller, Post } from '@midwayjs/core';
import { MesPurMaterialGroupVo } from '../dtos/mes_pur_material_group.dto';
import * as Mock from 'mockjs';
import { PurSupplierGroupVo, PurchaseState } from '../dtos/pur_supplier_group.dto';


@Controller('/mes/purchase/material')
export class PurchaseMaterialController {
  @Post('/getCombinedMaterialPurchaseOrderList')
  async getCombinedMaterialPurchaseOrderList() {
    // 用 Mock.js 生成符合 PurSupplierGroupVo DTO 的模拟数据
    const data: PurSupplierGroupVo[] = Mock.mock({
      'list|5': [ // 生成5个供应商
        {
          'supplierId|+1': 1000,
          'supplierName': '@cword(3,5)',
          'stateCountVoList|3-6': [
            {
              'state|1': [PurchaseState.待下单, PurchaseState.待发货, PurchaseState.待入库],
              'countNum|1-20': 1
            }
          ]
        }
      ]
    }).list;

    return {
      success: true,
      code: 200,
      count: data.length,
      data,
      ex: null
    };
  }

  @Post('/getCombinedPosAwaitingOrderList')
  async getCombinedPosAwaitingOrderList(): Promise<{ success: boolean; data: MesPurMaterialGroupVo[], total: number }> {
    const data: MesPurMaterialGroupVo[] = Mock.mock({
      'list|10': [
        {
          'idList|1-3': [() => Mock.Random.integer(1000, 9999)],
          'idListStr': '@id',
          'supplierId|1000-2000': 1,
          'supplierName': '@cword(3,6)',
          'factoryId|1000-2000': 1,
          'factoryName': '@cword(3,6)',
          'proCode': '@string("number", 6)',
          'colorName': '@color',
          'materialType|1-2': 1,
          'materialName': '@cword(2,5)',
          'materialCode': 'mb' + '@word(2,5)',
          'materialId|1000-2000': 1,
          'materialImg': '@image("100x100")',
          'planNum|100-1000': 1,
          'planPrices|1000-10000': 1,
          'realNum|100-1000': 1,
          'realPrices|1000-10000': 1,
          'inputNum|100-1000': 1,
          'inputPrices|1000-10000': 1,
          'willTime': '@datetime("yyyy-MM-dd HH:mm:ss")',
          'purType|1-3': 1,
          'attachList|0-2': [{}] // 可根据MesPurchaseAttach结构补充
        }
      ]
    }).list;
    return {
      success: true,
      total: data?.length,
      data
    };
  }


  @Post('/getPurchaseMaterialListByIds')
  async getPurchaseMaterialListByIds(): Promise<{ success: boolean; data: MesPurMaterialGroupVo[], total: number }> {
    const data: MesPurMaterialGroupVo[] = Mock.mock({
      'list|2': [
        {
          'idList|1-3': [() => Mock.Random.integer(1000, 9999)],
          'idListStr': '@id',
          'supplierId|1000-2000': 1,
          'supplierName': '@cword(3,6)',
          'factoryId|1000-2000': 1,
          'factoryName': '@cword(3,6)',
          'proCode': '@string("number", 6)',
          'colorName': '@color',
          'materialType|1-2': 1,
          'materialName': '@cword(2,5)',
          'materialCode': 'mb' + '@word(2,5)',
          'materialId|1000-2000': 1,
          'materialImg': '@image("100x100")',
          'planNum|100-1000': 1,
          'planPrices|1000-10000': 1,
          'realNum|100-1000': 1,
          'realPrices|1000-10000': 1,
          'inputNum|100-1000': 1,
          'inputPrices|1000-10000': 1,
          'willTime': '@datetime("yyyy-MM-dd HH:mm:ss")',
          'purType|1-3': 1,
          "doorWidth|1-1000": 16000,
          "doorUnit|1-3": 1,
          "weight|1-1000": 0,
          'attachList|0-2': [{}],
          planMoney: 100,
          inputMoney: 100,
          orderPrices: 100,
          orderNum: 100,
          applyMoney:100
        }

      ]
    }).list;
    return {
      success: true,
      total: data?.length,
      data
    };
  }


}